<template>
  <el-dialog
    title="设备详情"
    :close-on-click-modal="false"
    width="30%"
    :visible.sync="visible">
    <el-table
        stripe
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="pam"
        label="属性"
        width="180">
      </el-table-column>
      <el-table-column
        prop="dat"
        label="数据"
        width="300">
      </el-table-column>
    </el-table>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <!-- <el-button type="primary" @click="dataFormSubmit()">确定</el-button> -->
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        tableData:[],
        dataForm: {
          productKey: "",
          productName: "",
          deviceName: "",
          nickname: null,
          deviceSecret: "",
          iotId: "",
          utcCreate: "",
          gmtCreate: "",
          utcActive: null,
          gmtActive: null,
          status: "",
          firmwareVersion: null,
          nodeType: 0,
          region: ""
        },
      }
    },
    methods: {
      init (id) {
        // this.dataForm.devId = id || 0
        this.visible = true
        this.$nextTick(() => {
          if (id!=null) {
            this.$http({
              url: this.$http.adornUrl(`/iot/device/detail/${id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm = data.data;
// console.log(this.dataForm)
              this.tableData.push({"pam":"productKey","dat":this.dataForm.productKey})
              this.tableData.push({"pam":"productName","dat":this.dataForm.productName})
              this.tableData.push({"pam":"deviceName","dat":this.dataForm.deviceName})
              this.tableData.push({"pam":"nickname","dat":this.dataForm.nickname})
              this.tableData.push({"pam":"deviceSecret","dat":this.dataForm.deviceSecret})
              this.tableData.push({"pam":"iotId","dat":this.dataForm.iotId})
              this.tableData.push({"pam":"utcCreate","dat":this.dataForm.utcCreate})
              this.tableData.push({"pam":"gmtCreate","dat":this.dataForm.gmtCreate})
              this.tableData.push({"pam":"utcActive","dat":this.dataForm.utcActive})
              this.tableData.push({"pam":"gmtActive","dat":this.dataForm.gmtActive})
              this.tableData.push({"pam":"status","dat":this.dataForm.status})
              this.tableData.push({"pam":"productKey","dat":this.dataForm.productKey})
              this.tableData.push({"pam":"firmwareVersion","dat":this.dataForm.firmwareVersion})
              this.tableData.push({"pam":"nodeType","dat":this.dataForm.nodeType})
              this.tableData.push({"pam":"region","dat":this.dataForm.region})
          // productName: "",
          // deviceName: "",
          // nickname: null,
          // deviceSecret: "",
          // iotId: "",
          // utcCreate: "",
          // gmtCreate: "",
          // utcActive: null,
          // gmtActive: null,
          // status: "",
          // firmwareVersion: null,
          // nodeType: 0,
          // region: ""

              }
            })
          }
        })
      },
      // // 表单提交
      // dataFormSubmit () {
      //   this.$refs['dataForm'].validate((valid) => {
      //     if (valid) {
      //       this.$http({
      //         url: this.$http.adornUrl(`/iot/device/${!this.dataForm.devId ? 'save' : 'update'}`),
      //         method: 'post',
      //         data: this.$http.adornData({
      //           'devId': this.dataForm.devId || undefined,
      //           'productKey': this.dataForm.productKey,
      //           'deviceName': this.dataForm.deviceName,
      //           'deviceSecret': this.dataForm.deviceSecret,
      //           'deviceStatus': this.dataForm.deviceStatus,
      //           'iotId': this.dataForm.iotId
      //         })
      //       }).then(({data}) => {
      //         if (data && data.code === 0) {
      //           this.$message({
      //             message: '操作成功',
      //             type: 'success',
      //             duration: 1500,
      //             onClose: () => {
      //               this.visible = false
      //               this.$emit('refreshDataList')
      //             }
      //           })
      //         } else {
      //           this.$message.error(data.msg)
      //         }
      //       })
      //     }
      //   })
      // }
    }
  }
</script>
